package com.shuaige.paydollarapi.controller;

import com.shuaige.paydollarapi.model.PaymentRequest;
import com.shuaige.paydollarapi.paydoolar.secure.PaydollarSecureException;
import com.shuaige.paydollarapi.paydoolar.secure.PaydollarSecureUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Auther: hp
 * @Date: 2019/5/28 21:06
 * @Description:
 */
@Controller
public class HomeController {
    @RequestMapping(value = "/payment")
    public String index(ModelMap map) {
        map.put("orderRef", String.valueOf(System.currentTimeMillis()));
        return "/paydollar/index";
    }


    @RequestMapping(value = "/paymentSubmit")
    public String paymentSubmit(PaymentRequest paymentRequest, ModelMap map) throws PaydollarSecureException {
        String secureHash = PaydollarSecureUtil.generatePaymentSecureHash(paymentRequest.getMerchantId(), paymentRequest.getOrderRef(),
                paymentRequest.getCurrCode(), paymentRequest.getAmount(), paymentRequest.getPayType());
        map.put("secureHash", secureHash);
        map.put("merchantId", paymentRequest.getMerchantId());
        map.put("amount", paymentRequest.getAmount());
        map.put("orderRef", paymentRequest.getOrderRef());
        map.put("currCode", paymentRequest.getCurrCode());
        map.put("successUrl", paymentRequest.getSuccessUrl());
        map.put("failUrl", paymentRequest.getFailUrl());
        map.put("cancelUrl", paymentRequest.getCancelUrl());
        map.put("payType", paymentRequest.getPayType());
        map.put("lang", paymentRequest.getLang());
        map.put("mpsMode", paymentRequest.getMpsMode());
        map.put("payMethod", paymentRequest.getPayMethod());
        map.put("remark", paymentRequest.getRemark());
        map.put("redirect", paymentRequest.getRedirect());
        map.put("oriCountry", paymentRequest.getOriCountry());
        map.put("destCountry", paymentRequest.getDestCountry());

        System.out.println(paymentRequest);

        return "/paydollar/paymentSubmit";
    }


}
